package leetcode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * LeetCode题号: 189【旋转数组】
 * https://leetcode-cn.com/problems/rotate-array/
 */
public class RotateArray {
    public void rotate(int[] nums, int k) {
        Deque<Integer> deque = new LinkedList<>();
        for (int i = 0; i < nums.length; i++) {
            deque.addFirst(nums[i]);
        }
        for (int i = 0; i < k; i++) {
            deque.addFirst(deque.pollLast());
        }
        for (int i = 0; i < nums.length; i++) {
            nums[i] = deque.getFirst();
        }
    }
}
